Skip to content

Add specs for bare-bracket rejection in strict2 and self keyword#124

Open
aswamy wants to merge 1 commit into
mainfrom
bare-bracket-self-keyword
Open

Add specs for bare-bracket rejection in strict2 and self keyword#124
aswamy wants to merge 1 commit into
mainfrom
bare-bracket-self-keyword

Conversation

@aswamy
Copy link
Copy Markdown

@aswamy aswamy commented Mar 20, 2026

Summary

Adds conformance specs for the bare-bracket syntax changes in Shopify/liquid (28 specs total).

Bare-bracket rejection in strict2 (7 specs):

  • {{ ['product'] }}, {{ [key] }} are rejected with parse_error
  • Rejection applies in variables, for, if, case, assign

strict2 accepts qualified access (2 specs):

  • product['title'] and dot notation remain valid

self keyword (18 specs):

  • self['product'] resolves variables through the normal scope chain
  • self[key] performs dynamic variable lookups (key from environment OR local assign)
  • Works in all parsing modes (lax, strict, strict2)
  • Local assigns are visible via self['product']
  • self can be reassigned ({% assign self = 'value' %})
  • Returns empty string for unknown keys (lax and strict2)
  • Supports nested property access (self['product'].title)
  • Composes with other expressions: a[ self[ 'b' ] ], self[self['key1']]
  • Works inside for loop bodies and capture blocks
  • self keyword still resolves to SelfDrop even when environment defines a self key
  • QUIRK documented: self contains 'key' always returns false because contains calls include? and SelfDrop doesn't implement it — use self['key'] for definedness checks

Backwards compatibility (1 spec):

  • Lax mode still allows bare-bracket access

Depends on:

  • Shopify/liquid: #2060
  • Shopify/liquid-rewriter-private: #211

🤖 Generated with Claude Code

@aswamy aswamy added the #gsd:49922 Liquid Array Literal Support label Mar 20, 2026
Copy link
Copy Markdown

@karreiro karreiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR, @aswamy!

Could we make sure we cover the scenarios outlined in this file (reference)?

Thanks again for the PR!

- strict2 rejects bare-bracket access (['product'], [key], etc.)
- Qualified bracket access (product['title']) remains valid
- `self` keyword resolves variables through the scope chain
- `self` works in all parsing modes (lax, strict, strict2)
- Local assigns shadow the `self` keyword

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aswamy aswamy force-pushed the bare-bracket-self-keyword branch from 5a98157 to c841a82 Compare May 4, 2026 14:05
@aswamy aswamy marked this pull request as ready for review May 4, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

#gsd:49922 Liquid Array Literal Support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants